import json
import threading
from flask import Flask, jsonify, request
from flask_cors import CORS
from event import Event


app = Flask(__name__)
CORS(app)


# 定义一个路由，处理GET请求
@app.route('/data', methods=['GET'])
def send_data():
    send_data = {
        "A": None
    }

    return jsonify(send_data)


def check_format(data):
    # 要检查的字段列表
    fields_to_check = ['redis_host', 'redis_port', 'redis_pd', 'redis_password', 'redis_channel', 'format_str',
                       'threshold', 'route', 'gantry_info']
    # 检查并打印哪些字段存在或不存在于字典中
    for field in fields_to_check:
        if field not in data.keys():
            print(f"配置文件缺少字段 '{field}'！！！")
            return False
    if not data["gantry_info"]:
        print("未配置门架参数！！！")
        return False
    # info_to_check = ['up_gantry_id', 'down_gantry_id', 'dist', 'car_pass_time', 'car_max_speed', 'car_min_speed']
    # for gantry in data["gantry_info"]:
    #     for info in info_to_check:
    #         if info not in gantry.keys():
    #             print(f"门架参数缺少字段 '{info}'！！！")
    #             return False
    return True


if __name__ == "__main__":
    file_path = r"/home/gj/Download/新建文件夹/卡口相机.log"
    try:
        event = Event(file_path)
        event.init()
        # app.run(host='10.100.72.88', port=5001)
        # threading.Thread(target=lambda: app.run(host='10.129.0.23', port=5001, use_reloader=False)).start()
        event.data_split()
        event.run()
    except Exception as e:
        print("Error", e)
